# Contributor: Hugo Osvaldo Barrera <hugo@whynothugo.nl>
maintainer="Hugo Osvaldo Barrera <hugo@whynothugo.nl>"
pkgname=mml
pkgver=1.0.0
pkgrel=0
pkgdesc="Command line tool for MIME message Meta Language"
url="https://github.com/soywod/mml"
# s390x: nix/libc crate
# riscv64: ftbfs, segfault
# loongarch64: blocked by libc crate
arch="all !s390x !riscv64 !loongarch64"
license="MIT"
makedepends="cargo cargo-auditable"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="shotman-$pkgver.tar.gz::https://github.com/soywod/mml/archive/refs/tags/v$pkgver.tar.gz"
options="net" # fetch dependencies

prepare() {
	default_prepare

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --release --frozen
	./target/release/mml completion bash > $pkgname.bash
	./target/release/mml completion fish > $pkgname.fish
	./target/release/mml completion zsh > $pkgname.zsh
	./target/release/mml man ./
}

check() {
	cargo test --frozen
}

package() {
	install -Dm 0755 target/release/$pkgname "$pkgdir/usr/bin/$pkgname"

	install -Dm644 $pkgname.bash \
		"$pkgdir"/usr/share/bash-completion/completions/$pkgname
	install -Dm644 $pkgname.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/$pkgname.fish
	install -Dm644 $pkgname.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_$pkgname

	install -Dm 0644 mml-compile.1 "$pkgdir/usr/share/man/man1/mml-compile.1"
	install -Dm 0644 mml-completion.1 "$pkgdir/usr/share/man/man1/mml-completion.1"
	install -Dm 0644 mml-interpret.1 "$pkgdir/usr/share/man/man1/mml-interpret.1"
	install -Dm 0644 mml-man.1 "$pkgdir/usr/share/man/man1/mml-man.1"
	install -Dm 0644 mml.1 "$pkgdir/usr/share/man/man1/mml.1"
}

sha512sums="
2e164288c7e9de283427cf4d80f234b1db3d9eb252e2cfbf87b5a2e81148f2d7ad473242cea7afe2ea9cc11447de08c824e8dd72faf63fe537225f9b5de8e6f8  shotman-1.0.0.tar.gz
"
